package com.example.zqh.controller;


import com.example.zqh.model.RespBean;
import com.example.zqh.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 邓龙飞
 * @since 2022-09-10
 */
@RestController
@RequestMapping("/order")
@Api(tags = "订单表的增删改查")
public class PurchaseController {

    @Autowired
    OrderService orderService;

    /**
      * @Author: 邓龙飞
      * @Date:
      * @Description: 生成一个订单
    */
    @ApiOperation(value = "生成一个订单")
    @PostMapping("generateAnOrder")
    public RespBean generateAnOrder(Integer number, Integer food_id, Principal principal){
        return orderService.generateAnOrder(number,food_id,principal);
    }

    /**
      * @Author: 邓龙飞
      * @Date:
      * @Description: 取消订单（退货）
    */
    @ApiOperation(value = "取消订单，退款")
    @PostMapping("cancelOrder")
    public RespBean cancelOrder(Integer id,Principal principal){
        return orderService.cancelOrder(id, principal);
    }

    /**
      * @Author: 邓龙飞
      * @Date:
      * @Description: 确定订单以后，该订单将会在数据库中消失（相当于删除订单）
    */
    @ApiOperation(value = "删除订单接口，（确定收货以后就会删除订单）")
    @DeleteMapping("deleteOrderInterface")
    public RespBean deleteOrderInterface(Integer id) {
        return orderService.deleteOrderInterface(id);
    }

    /**
      * @Author: 邓龙飞
      * @Date:
      * @Description: 查询属于自己的订单
    */
    @ApiOperation(value = "查询自己的订单(不做分页)")
    @GetMapping("inquireAboutYourOrder")
    public RespBean inquireAboutYourOrder(Principal principal){
        return orderService.inquireAboutYourOrder(principal);
    }

}

